// function generate100BlueColors() {
//   const colors: string[] = [];
//   // b
//   for (let i = 0; i < 5; i++) {
//     // g
//     for (let j = 0; j < 5; j++) {
//       // r
//       for (let k = 0; k < 4; k++) {
//         colors.push(`rgb(${10 * i}, ${120 - 10 * j}, ${255 - 20 * k})`);
//       }
//     }
//   }
//   return colors;
// }

const blueColors = [
  // sky
  // 200
  '#bae6fd',
  // 300
  '#7dd3fc',
  // 400
  '#38bdf8',
  // 500
  '#0ea5e9',
  // 600
  '#0284c7',

  // blue
  // 200
  '#bfdbfe',
  // 300
  '#93c5fd',
  // 400
  '#60a5fa',
  // 500
  '#3b82f6',
  // 600
  '#2563eb',

  // '#1A6CFE',
].reverse();

// export function getBlueColor(index: number, total: number) {
//   const interval = Math.ceil(blueColors.length / total);
//   return blueColors[(index * interval) % blueColors.length];
// }

export function getBlueColor(index: number) {
  return blueColors[index % blueColors.length];
}

const greenColors = [
  // lime
  // 200
  '#d9f99d',
  // 300
  '#bef264',
  // 400
  '#a3e635',
  // 500
  '#84cc16',
  // 600
  '#65a30d',

  // green
  // 200
  '#bbf7d0',
  // 300
  '#86efac',
  // 400
  '#4ade80',
  // 500
  '#22c55e',
  // 600
  '#16a34a',

  // '#56D433',
].reverse();

export function getGreenColor(index: number) {
  return greenColors[index % greenColors.length];
}

export const dateFormatterMap = new Map<string, string>([
  ['day', 'YYYY-MM-DD'],
  ['date', 'YYYY-MM-DD'],
  ['month', 'YYYY-MM'],
  ['year', 'YYYY'],
]);
export const selectTypeMap = new Map<string, string>([
  ['day', 'date'],
  ['month', 'dateMonth'],
  ['year', 'dateYear'],
]);
/**
 * 列转行
 * @param arr
 * @param isDay
 */
export const rowToColumns = (arr: any[], isDay = true) => {
  const resultMap: Record<string, Record<string, any>> = {};

  arr.forEach((item) => {
    const {
      date,
      deviceName,
      chargeCapacity,
      dischargeCapacity,
      chargeTimes,
      dischargeTimes,
      reportId,
      stationId,
      stationName,
      startTime,
      endTime,
    } = item;

    // 如果 date 不存在，初始化
    // 如果是日维度，要取时间段，反之取日期
    if (!resultMap[isDay ? startTime : date]) {
      resultMap[isDay ? startTime : date] = {
        date: date,
        reportId,
        stationId,
        stationName,
        startTime,
        endTime,
      };
    }

    // 使用 areaName 作为前缀，构造新的字段名
    const areaPrefix = deviceName;
    resultMap[isDay ? startTime : date][`${areaPrefix}_chargeCapacity`] = chargeCapacity;
    resultMap[isDay ? startTime : date][`${areaPrefix}_dischargeCapacity`] = dischargeCapacity;
    resultMap[isDay ? startTime : date][`${areaPrefix}_chargeTimes`] = chargeTimes;
    resultMap[isDay ? startTime : date][`${areaPrefix}_dischargeTimes`] = dischargeTimes;
  });

  console.log('我这里导出下转换后的', resultMap);

  // 将对象转换为数组
  return Object.values(resultMap);
};
